package com.hg.controller;

import com.hg.pojo.ItemParam;
import com.hg.service.IItemParamService;
import com.hg.util.PageResult;
import com.hg.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 商品规则参数 前端控制器
 * </p>
 *
 * @author Baomidou
 * @since 2025-07-30
 */
@RestController
@RequestMapping("/backend/itemParam")
public class ItemParamController {
    @Autowired
    private IItemParamService itemParamService;

    @RequestMapping("/selectItemParamByItemCatId/{itemCatId}")
    public Result selectItemParamByItemCatId(@PathVariable Long itemCatId) {
        try {
            ItemParam itemParam = itemParamService.selectItemParamByItemCatId(itemCatId);
            return Result.ok(itemParam);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败");
        }
    }

    @RequestMapping("/selectItemParamAll")
    public Result selectItemParamAll() {
        try {
            PageResult pageResult = itemParamService.selectItemParamAll();
            return Result.ok(pageResult);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败");
        }
    }

    @RequestMapping("/insertItemParam")
    public Result insertItemParam(Long itemCatId,String paramData) {
        try {
            itemParamService.insertItemParam(itemCatId,paramData);
            return Result.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("添加失败");
        }
    }
    @RequestMapping("/deleteItemParamById")
    public Result deleteItemParamById(Integer id) {
        try {
            itemParamService.deleteItemParamById(id);
            return Result.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("删除失败");
        }
    }
}
